package com.ruoyi.common.domain.light;

import java.time.Duration;
import java.time.LocalDate;
import java.time.LocalDateTime;

import com.baomidou.mybatisplus.annotation.TableField;

import java.io.Serializable;
import java.util.List;

import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.annotation.TableId;
import com.fasterxml.jackson.annotation.JsonGetter;
import com.ruoyi.common.enums.LightErrStatusEnum;
import com.ruoyi.common.enums.LightStatusEnum;
import com.ruoyi.common.mybatisplus.QueryWr;
import com.ruoyi.common.typehandler.ListTypeHandler;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

/**
 * 安灯异常处理记录表 lit_err
 *
 * @author ruoyi
 * @date 2022-02-24
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@TableName("lit_err")
public class LitErr implements Serializable {


    private static final long serialVersionUID = 1L;

    /**
     * $column.columnComment
     */
    @TableId
    private Long id;
    /**
     * 异常工单号
     */
    private String errNo;
    /**
     * 设备id
     */
    private Long deviceId;
    /**
     * 安灯状态
     */
    private LightStatusEnum litStatus;
    /**
     * 异常id
     */
    @QueryWr(ignore = true)
    private Long errId;
    /**
     * 一级异常类别
     */
    private Long errIdLv1;
    /**
     * 二级异常类别
     */
    private Long errIdLv2;
    /**
     * 异常图片
     */

    @TableField(typeHandler = ListTypeHandler.class)
    private List<String> errPics;

    private LocalDateTime initTime;
    private String initBy;
    /**
     * 签到时间
     */
    private LocalDateTime signTime;
    /**
     * 签到响应时长
     */
    private Long signCostTimes;
    /**
     * 签到人
     */
    private String signBy;
    /**
     * 异常解除时间
     */
    private LocalDateTime liftTime;
    /**
     * 异常处理时长
     */
    private Long liftCostTimes;
    /**
     * 异常解除人
     */
    private String liftBy;
    /**
     * 异常持续时长
     */
    private Long errCostTimes;

    private String remark;

    private LocalDateTime updateTime;
    private String updateBy;
    private LightErrStatusEnum status;
    private String dingdingTaskId;
    private Integer dingdingTaskStatus;

    @TableField(exist = false)
    private LocalDate beginTime;
    @TableField(exist = false)
    private LocalDate endTime;

    @JsonGetter("errCostTimes")
    public long errCostTimes() {
        if (getErrCostTimes() == null) {
            Duration between = Duration.between(getInitTime(), LocalDateTime.now());
            return between.toSeconds();
        } else {
            return getErrCostTimes();
        }

    }
}